package com.myblog.controller;

import com.myblog.Utils.BeanCopyUtils;
import com.myblog.domain.GlobalResponse;
import com.myblog.domain.Vo.MenuVo;
import com.myblog.domain.entity.Menu;
import com.myblog.services.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/system/menu")
public class MenuController {

    @Resource
    MenuService menuService;
    @GetMapping("/list")
    public GlobalResponse getMenu(String status,String menuName){
        return menuService.getMenu(status,menuName);
    }

    @PostMapping
    public  GlobalResponse saveMenu(@RequestBody Menu menu){
        return menuService.saveMenu(menu);
    }

    @GetMapping("{id}")
    public GlobalResponse getMenu(@PathVariable String id){
        return GlobalResponse.ok(BeanCopyUtils.copyBean(menuService.getById(id), MenuVo.class));
    }

    @PutMapping()
    public GlobalResponse updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }

    @DeleteMapping("/{menuId}")
    public GlobalResponse deleteMenu(@PathVariable String menuId){
        return menuService.deleteMenu(menuId);

    }

    @GetMapping("/treeselect")
    public  GlobalResponse getMenuTree(){
        return menuService.getMenuTree();
    }

    @GetMapping("/roleMenuTreeselect/{id}")
    public GlobalResponse getRoleMenuTree(@PathVariable Long id){
        return menuService.getRoleMenuTree(id);
    }

}
